<?php
require_once(dirname(__FILE__).'/../include/config.inc.php');
header('Content-type: application/json;charset=utf-8');
$url="https://w.url.cn/s/AdO9Mr6";
$true_url="http://hty.hnbest.com";
if(isset($url)){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
	//curl_setopt($ch, CURLOPT_POST, 1);
	//curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
	$html = curl_exec($ch);
	var_dump($html);
	$num=strpos($html,'weixin110.qq.com');
	if($num){
		$time=date("Y-m-d H:i:s",time());
		//封装为json格式的数据
		$json='{
		  "touser": "oB8ZK1AS39XvcBhM8me8WRYfHN7s" ,  
		  "template_id": "cjXcmmMtT6yP5OJ99k8KirHq6D4H6Rv_LwhrQOgIJcI",    
		  "url":"'.$true_url.'",         
		  "data": {
				  "first": {
					  "value": "您好，网络故障，请及时处理！", 
					  "color": "#f71b03"
				  }, 
				  "keyword1": {
					  "value": "'.$time.'", 
					  "color": "#173177"
				  }, 
				  "keyword2": {
					  "value": "网页被暂停", 
					  "color": "#173177"
				  },
				  "remark": {
					  "value": "故障页面:'.$true_url.'请点击查看详情", 
					  "color": "#f71b03"
				  } 
		  }
		}';

		/* 发送消息 */
		require_once "WxApi.php";
		require_once "WxConfig.php";
		require_once(dirname(__FILE__).'/../jssdk.php');
		$appId=WxConfig::APPID;
		$appSecret=WxConfig::APPSECRET;
		$jssdk = new JSSDK($appId, $appSecret);
		$g_AccessToken=$jssdk->getAccessToken();
		if(isset($g_AccessToken)){
			$uuu="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$g_AccessToken;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $uuu);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  //https协议
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
			$html = curl_exec($ch);
			$txt_name=dirname(__FILE__)."/txt/".time()."-checkdomain-sendWxMsg.txt";
			file_put_contents($txt_name,serialize($html));
		}

	}
	
}

